package com.dancun.controller;


import com.dancun.entity.*;
import com.dancun.entity.Manager;
import com.dancun.service.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.NoHandlerFoundException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-10-02
 */
@RestController

public class ManagerController {
    @Autowired
    IManagerService managerService;

    /**
     * 登录
     *
     * @return
     */
    @RequestMapping("/admin")
    public ModelAndView login(Manager manager) {
        ModelAndView mav = new ModelAndView("/Main/index.jsp");
        Map<String, Object> map = new HashMap<>();
        map.put("name", manager.getName());
        map.put("pwd", manager.getPwd());
        if (managerService.listByMap(map).size() != 0) {
            mav.addObject("manager", managerService.listByMap(map).get(0));
            return mav;
        }
        mav.setViewName("/Admin.html");
        return mav;
    }


    /**
     * 学生表
     *
     * @return
     */
    @Autowired
    IStudentService studentService;

    @RequestMapping("/Mstulist")
    public ModelAndView Mstulist() {
        ModelAndView mav = new ModelAndView("/Main/M_StudentList.jsp");
        List<Student> stu = studentService.list();
        mav.addObject("list", stu);
        return mav;
    }

    /**
     * 教师表
     *
     * @return
     */
    @Autowired
    ITeacherService teacherService;

    @RequestMapping("/listTeacher")
    public ModelAndView listTeacher() {
        ModelAndView mav = new ModelAndView("/Main/M_TeacherList.jsp");
        List<Teacher> tea = teacherService.list();
        mav.addObject("list", tea);
        return mav;
    }


}


